package com.ks.user.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ks.core.base.OperationContext;
import com.ks.core.constant.Const;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.user.controller.dto.ApBaseRequest;
import com.ks.user.entity.ApBase;
import com.ks.user.entity.DashboadBase;
import com.ks.user.dao.DashboadBaseMapper;
import com.ks.user.entity.LogOperatelog;
import com.ks.user.service.IDashboadBaseService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ks.user.service._ServiceBase;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 看板-系统中的看板清单 服务实现类
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-24
 */
@Service
public class DashboadBaseServiceImpl extends _ServiceBase<DashboadBaseMapper, DashboadBase> implements IDashboadBaseService {

    @Resource
    private  DashboadBaseMapper dashboadBaseMapper;

    @Override
    public Map<String, Object> selectDashboadBase(OperationContext context, ApBaseRequest apBaseRequest) {
        DashboadBase dashboadBase = new DashboadBase();
        EntityWrapper<DashboadBase> wrapper = new EntityWrapper<>();
        dashboadBase.setApID(apBaseRequest.getId());
        dashboadBase.setDelMark(Const.DEL_FLAG_NORMAL);
        dashboadBase.setTenantID(context.getTenantId().intValue());
        dashboadBase.setOrgID(context.getOrgId().intValue());
        dashboadBase.setOrgSubID(context.getOrgSubId().intValue());
        wrapper.setEntity(dashboadBase);
        List<DashboadBase> dashboadBases = dashboadBaseMapper.selectList(wrapper);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", dashboadBases);
        return resultMap;
    }

    @Override
    public int addDashboadBase(OperationContext context, DashboadBase dashboadBase) {
        Integer i = dashboadBaseMapper.insert(dashboadBase);
        return i;
    }

    @Override
    public int updateDashboadBase(OperationContext context, DashboadBase dashboadBase) {
        Integer i = dashboadBaseMapper.updateById(dashboadBase);
        LogOperatelog logOperatelog = new LogOperatelog();
        logOperatelog.setActionName("应用看板修改操作");
        logOperatelog.setApplicationName("看板模块");
        logOperatelog.setMainDataId(1);
        logOperatelog.setMainDataType("log_operatelog");
        logOperatelog.setParameter("");
        logOperatelog.setRemark("");
        this.WriteOperateLog(OperateLogInfo(context,logOperatelog));
        return i;
    }

    @Override
    public int deleteDashboadBase(OperationContext context,ApBaseRequest apBaseRequest) {
        DashboadBase dashboadBase = new DashboadBase();
        dashboadBase.setId(apBaseRequest.getId());
        Integer i = dashboadBaseMapper.deleteById(dashboadBase);
        if(i>0){
            LogOperatelog logOperatelog = new LogOperatelog();
            logOperatelog.setActionName("应用看板删除操作");  //操作名称
            logOperatelog.setApplicationName("看板模块");
            logOperatelog.setMainDataId(apBaseRequest.getId());
            logOperatelog.setMainDataType("log_operatelog");
            logOperatelog.setParameter("");
            logOperatelog.setRemark("");
            this.WriteOperateLog(OperateLogInfo(context,logOperatelog));
        }
        return i;
    }

    @Override
    public Map<String, Object> selectBaseSys(OperationContext context, ApBaseRequest apBaseRequest) {
        DashboadBase dashboadBase = new DashboadBase();
        EntityWrapper<DashboadBase> wrapper = new EntityWrapper<>();
        dashboadBase.setApID(apBaseRequest.getId());
        dashboadBase.setDelMark(Const.DEL_FLAG_NORMAL);
        dashboadBase.setDataType("SYS");
        wrapper.setEntity(dashboadBase);
        List<DashboadBase> dashboadBases = dashboadBaseMapper.selectList(wrapper);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", dashboadBases);
        return resultMap;
    }
}
